package com.start.platform.core.security;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.start.common.constant.StartConstant;
import com.start.common.user.UserManageInfoService;
import com.start.platform.core.entity.StartPlatformFans;
import com.start.platform.core.entity.StartPlatformUserEntity;
import com.start.platform.core.service.StartPlatformFansService;
import com.start.platform.core.service.StartPlatformUserService;
import com.start.platform.core.vo.StartPlatformUserDetail;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;


public class StartPlatformUserInfoLoadService implements UserManageInfoService<StartPlatformUserEntity> {

    @Autowired
    private StartPlatformUserService platformUserService;
    @Autowired
    private StartPlatformFansService startPlatformFansService;

    @Override
    public String getLoadUserType() {
        return StartConstant.ClientUserType.PLATFORM_USER;
    }

    /**
     * 获取用户好友信息
     *
     * @param ids
     * @return
     */
    @Override
    public List<StartPlatformUserEntity> getByUserIds(Collection<? extends Serializable> ids) {
        return platformUserService.list(new LambdaQueryWrapper<StartPlatformUserEntity>().in(StartPlatformUserEntity::getId, ids));
    }

    @Override
    public StartPlatformUserDetail getByUserId(Serializable userId) {
        StartPlatformUserEntity userEntity = platformUserService.getById(userId);
        Map<String, Map<String, StartPlatformFans>> userFans = startPlatformFansService.getUserFansMap(userEntity.getId());
        return StartPlatformUserDetail.create(userEntity, userFans);
    }
}
